package com.fndsoft.logstorage.ui;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.fndsoft.logstorage.R;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

public class LogActivity extends Activity {
	private TextView textView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.log_activity);
		textView = (TextView) findViewById(R.id.tv);
		textView.setMovementMethod(ScrollingMovementMethod.getInstance());
		String path = Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator;
		File file = new File(path+"bobos" + File.separator + "new1.txt");
		if(file.exists()) {
			textView.setText(readerLog(file).toString());
		}else {
			textView.setText("文件不存在");
		}
		//textView.setText(readerLog(String path));
	}
	
	private StringBuffer readerLog(File f) {
		StringBuffer sb = new StringBuffer();
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
			String line = "";
			while((line = br.readLine()) != null) {
				sb.append(line);
				sb.append("\n");
			}
			br.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb;
	}
}
